#include "junix.h"
using namespace std;

struct A
{
	int i;
	int j;

	A(int ii=0,int jj=0):i(ii),j(jj){ }
    void print_i()
    {
    	cout<<i<<" ";
    }

    void print_j()
    {
    	cout<<j<<" ";
    }

    int geti(){ return i;}
    int getj(){ return j;}
};

int main(int argc, char **argv)
{
	srand(time(0));
	vector<int> vi(20);
	vector<A> va;
	generate(vi.begin(),vi.end(),
			boost::bind( modulus<int>(), 
				boost::bind(rand), 20));

	BOOST_FOREACH(int i, vi)
	{
		va.push_back( A(i,rand()%20));
	}

	for_each(va.begin(), va.end(),
			boost::mem_fn(&A::print_i));
	cout<<endl;

	vector<A>::iterator pos;
	pos=max_element(va.begin(), va.end(),
			boost::bind( less<int>(), 
				boost::bind(&A::i, _1),
				boost::bind(&A::i, _2)));
	pos->print_i();
	cout<<endl;

	for_each(va.begin(),va.end(),
			mem_fun_ref(&A::print_j));
	cout<<endl;

	pos=min_element( va.begin(), va.end(),
			boost::bind( less<int>(),
				boost::bind(&A::j,_1),
				boost::bind(&A::j,_2)));
	pos->print_j();
	cout<<endl;
}
